import axios from 'axios'

const http = axios.create({
    baseURL: '/api'
})


http.interceptors.request.use(config => {
    let token = window.localStorage.getItem('token')
    if (token) {
        config.headers.authorization = 'token ' + token
    }
    return config
}, err => {
    return Promise.reject(err)
})


http.interceptors.response.use(res => {
    const { data, status } = res;
    if (status == 200) {
        return data
    }
}, err => {
    return Promise.reject(err)
})

export default http